/*
 * ECARX Technology Limited is the owner of the copyright and the trade secret of this software.
 * Without permission, no one has the right to obtain, disclose or use this software in any way.
 */

package com.ecarx.systemui.plugin.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import com.ecarx.systemui.plugin.ui.dialog.VolumeDialog;
import com.ecarx.systemui.plugin.ui.dialog.base.DialogManager;
import com.ecarx.systemui.plugin.utils.LogUtils;
import com.ecarx.systemui.plugin.PluginContext;
import com.ecarx.systemui.plugin.utils.ThreadUtils;
import com.ecarx.systemui.plugin.volume.IVolumeAidlInterface;

public class SettingsVolumeService extends Service {
    private static final String TAG = "SettingsVolumeServiceTag";

    public SettingsVolumeService() {
    }

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtils.d(TAG,"onCreate");
    }

    final IVolumeAidlInterface.Stub binder = new IVolumeAidlInterface.Stub() {
        @Override
        public void showVolumeDialog() throws RemoteException {
            PluginContext instance = PluginContext.getInstance();
            if(instance == null){
                LogUtils.e(TAG,"PluginContextUtils IS NULL, please fist init");
                return;
            }
            ThreadUtils.postDelayOnMain(0, new Runnable() {
                @Override
                public void run() {
                    DialogManager.getDialogManager().showVolumeDialog(instance.getPluginContext(), true);
                }
            });

        }

        @Override
        public void updateVolumeDialog() throws RemoteException {

        }

        @Override
        public void dismissVolumeDialog() throws RemoteException {

        }

        @Override
        public boolean volumeDialogIsShow() throws RemoteException {
            VolumeDialog volumeDialog = DialogManager.getDialogManager().getVolumeDialog();
            return volumeDialog != null && volumeDialog.isShowing();
        }
    };

    @Override
    public IBinder onBind(Intent intent) {
        LogUtils.d(TAG,"onBind");
        return binder;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();

    }
}